import 'dart:async';

main(List<String> args) {
  StreamController controller = StreamController();
  // controller.stream.take(4);

  // controller.stream.listen((data)=> print(data));
  var st =
      StreamTransformer<int, String>.fromHandlers(handleData: (int data, sink) {
    if (data == 678901) {
      sink.add("密码输入正确,正在开锁。。。");
    } else {
      sink.add("密码输入错误...");
    }
  });
  controller.stream
      .take(4) //只监听前四个
      .map((i) => ++i)
      // .transform(st)
      .listen((data) => print(data), onDone: () => print('完成'));
  controller.sink.add(143433);
  controller.sink.add(2);
  controller.sink.add(3);
  controller.sink.add(4);
  controller.sink.add(5);
}
